<?php
define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');

$action = isset($_GET['a'])?trim($_GET['a']):'';

$function = array(
		'zhuozhiStream'
);

if (empty($action) || !in_array($action, $function))
{
	echo json_encode(array('status'=>2,'notes'=>'方法错误'));
	exit();
}

if ( $action=='zhuozhiStream' )
{
	$result = array('status'=>2,'notes'=>'未知错误');
	$json = $GLOBALS["HTTP_RAW_POST_DATA"];
	$arr = json_decode($json,true);
	if (empty($arr['orderId']))
	{
		$result['notes'] = '订单号为空'; 
	}
	elseif (empty($arr['wayBillNo']))
	{
		$result['notes'] = '运单号为空';
	}
	elseif ($arr['logisticsname']!='圆通')
	{
		$result['notes'] = '物流企业名称错误';
	}
	else 
	{
		$sql = "SELECT order_id,invoice_no FROM ".$GLOBALS['ecs']->table('order_info')." WHERE pp_sn='$arr[orderId]'";
		$order = $GLOBALS['db']->getRow($sql);
		if ($order['order_id']>0)
		{
			$invoiceStr = $order['invoice_no'];
			$arr['wayBillNo'] = trim($arr['wayBillNo']);
			if (strpos($invoiceStr, $arr['wayBillNo']) === false)
			{
				$invoice_no = $invoiceStr.','.$arr['wayBillNo'];
				$sql = "UPDATE ".$GLOBALS['ecs']->table('order_info')." SET invoice_no='".$invoice_no."' WHERE pp_sn=$arr[orderId] ";
				$GLOBALS['db']->query($sql);
			}
			$result['status'] = '1';
			$result['notes'] = '';
		}
		else 
		{
			$result['notes'] = '找不到改订单记录';
		}

		
	}
	echo json_encode($result);
	exit();
}